

package Formularios;


import Clases.ConexionMySql;
import Clases.Proveedor;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


public class proveedor extends javax.swing.JFrame {
private DefaultTableModel busqueda;
  
    public proveedor() {
        initComponents();
        llamar();
        
        codigo_proveedor.setEnabled(false);
        razon_proveedor.setEnabled(false);
        ruc_proveedor.setEnabled(false);
        ci_proveedor.setEnabled(false);
        timbrado_proveedor.setEnabled(false);
        vencimiento_proveedor.setEnabled(false);
        direccion_proveedor.setEnabled(false);
        telefono_proveedor.setEnabled(false);
        contacto_proveedor.setEnabled(false);
        fax_proveedor.setEnabled(false);
        contribuyente_proveedor.setEnabled(false);
        agregar_proveedor.setEnabled(false);
        eliminar_proveedor.setEnabled(false);
        editar_proveedor.setEnabled(false);
    }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        codigo_proveedor = new javax.swing.JTextField();
        razon_proveedor = new javax.swing.JTextField();
        ruc_proveedor = new javax.swing.JTextField();
        ci_proveedor = new javax.swing.JTextField();
        timbrado_proveedor = new javax.swing.JTextField();
        direccion_proveedor = new javax.swing.JTextField();
        telefono_proveedor = new javax.swing.JTextField();
        fax_proveedor = new javax.swing.JTextField();
        contacto_proveedor = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        contribuyente_proveedor = new javax.swing.JComboBox();
        agregar_proveedor = new javax.swing.JButton();
        eliminar_proveedor = new javax.swing.JButton();
        editar_proveedor = new javax.swing.JButton();
        nuevo_proveedor = new javax.swing.JButton();
        vencimiento_proveedor = new com.toedter.calendar.JDateChooser();
        jLabel1 = new javax.swing.JLabel();
        atras_proveedor = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        proveedor_busqueda = new javax.swing.JTextField();
        buscar_nombre = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        vista = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(0));

        jLabel2.setText("Codigo:");

        jLabel3.setText("Razón Social:");

        jLabel4.setText("RUC:");

        jLabel5.setText("Nro. C.I.:");

        jLabel6.setText("Timbrado:");

        jLabel7.setText("Dirección:");

        jLabel8.setText("Teléfono:");

        jLabel9.setText("Fax:");

        jLabel10.setText("Contacto:");

        jLabel11.setText("Contribuyente:");

        razon_proveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                razon_proveedorActionPerformed(evt);
            }
        });

        jLabel13.setText("Vencimiento de timbrado:");

        contribuyente_proveedor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Si", "No" }));

        agregar_proveedor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/guardar.png"))); // NOI18N
        agregar_proveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_proveedorActionPerformed(evt);
            }
        });

        eliminar_proveedor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/excluded.png"))); // NOI18N
        eliminar_proveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eliminar_proveedorActionPerformed(evt);
            }
        });

        editar_proveedor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/editar.png"))); // NOI18N
        editar_proveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editar_proveedorActionPerformed(evt);
            }
        });

        nuevo_proveedor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/agregar.gif"))); // NOI18N
        nuevo_proveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nuevo_proveedorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel3)
                                .addComponent(jLabel4)
                                .addComponent(jLabel5))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel6)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel8)
                                        .addComponent(jLabel7)
                                        .addComponent(jLabel9)))
                                .addGap(17, 17, 17)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(timbrado_proveedor, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                                    .addGap(19, 19, 19)
                                    .addComponent(jLabel13)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(vencimiento_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(telefono_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(fax_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(38, 38, 38)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addComponent(jLabel11)
                                            .addGap(29, 29, 29)
                                            .addComponent(contribuyente_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(0, 0, Short.MAX_VALUE))
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addComponent(jLabel10)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(contacto_proveedor))))
                                .addComponent(direccion_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(razon_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(codigo_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(ci_proveedor, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                                .addComponent(ruc_proveedor, javax.swing.GroupLayout.Alignment.LEADING)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 195, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(agregar_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(eliminar_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(editar_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)))
                .addComponent(nuevo_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(51, 51, 51))
            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(codigo_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(razon_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(ruc_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(ci_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(timbrado_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel13))
                    .addComponent(vencimiento_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(direccion_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(telefono_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(contacto_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(fax_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(contribuyente_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(eliminar_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(agregar_proveedor)
                    .addComponent(editar_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(nuevo_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24))
        );

        jLabel1.setFont(new java.awt.Font("Arial Narrow", 3, 30)); // NOI18N
        jLabel1.setText("Proveedores");

        atras_proveedor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/close.png"))); // NOI18N
        atras_proveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atras_proveedorActionPerformed(evt);
            }
        });

        jLabel14.setText("Nombre: ");

        buscar_nombre.setText("Buscar");
        buscar_nombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscar_nombreActionPerformed(evt);
            }
        });

        vista.setBackground(new java.awt.Color(204, 204, 204));
        vista.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Nombre", " RUC", "Doc. Identidad", "Timbrado", "Vencimiento", "Direccion", "Telefono", "Contacto", "Fax", "Contribuyente"
            }
        ));
        vista.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                vistaMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(vista);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(310, 310, 310)
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(proveedor_busqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(buscar_nombre)
                                .addGap(18, 18, 18)
                                .addComponent(atras_proveedor)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel14)
                        .addComponent(proveedor_busqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(buscar_nombre))
                    .addComponent(atras_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(53, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void razon_proveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_razon_proveedorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_razon_proveedorActionPerformed

    private void atras_proveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atras_proveedorActionPerformed
        atras();// TODO add your handling code here:
    }//GEN-LAST:event_atras_proveedorActionPerformed

    private void buscar_nombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscar_nombreActionPerformed

        ConexionMySql sqlserver = new ConexionMySql();
        Connection cnn = sqlserver.conectar();
        String[] titulos = {"Codigo","Nombre","RUC","Doc Identidad","Timbrado","Vencimiente","Direccion","Telefono","Contacto","Fax","Contriyuyente"};
        busqueda = new DefaultTableModel(null,titulos);
        String [] registro = new String[12];
        String id = (proveedor_busqueda.getText());
        String sql = "SELECT codigo_proveedor, razon_proveedor ,ruc_proveedor ,ci_proveedor ,timbrado_proveedor ,vencimiento_proveedor ,direccion_proveedor ,telefono_proveedor ,contacto_proveedor ,fax_proveedor ,contribuyente_proveedor FROM proveedor where razon_proveedor LIKE '%" + id +"%'";
        try
        {
            Statement st = cnn.createStatement();
            ResultSet rs = st.executeQuery(sql);

            while(rs.next()){
                registro[0]= rs.getString(1);
                registro[1]= rs.getString(2);
                registro[2]= rs.getString(3);
                registro[3]= rs.getString(4);
                registro[4]= rs.getString(5);
                registro[5]= rs.getString(6);
                registro[6]= rs.getString(7);
                registro[7]= rs.getString(8);
                registro[8]= rs.getString(9);
                registro[9]= rs.getString(10);
                registro[10]= rs.getString(11);
                
                busqueda.addRow(registro);
            }
            vista.setModel(busqueda);
        }
        catch (SQLException e)
        {
            JOptionPane.showMessageDialog(null, e);

        }
    }//GEN-LAST:event_buscar_nombreActionPerformed

    private void vistaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_vistaMouseClicked
        int filasel = vista.getSelectedRow();
        String valor = (String) busqueda.getValueAt(filasel,0);
        PasarTabla(valor);
    }//GEN-LAST:event_vistaMouseClicked

    private void agregar_proveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_proveedorActionPerformed
        ConexionMySql con= new ConexionMySql();
        Connection reg= con.conectar();
        System.out.println("Conexion establecida");
        SimpleDateFormat fecha= new SimpleDateFormat("yyyy-MM-dd");
        Proveedor proveedor  = new Proveedor();
       
        //proveedor.setCi_proveedor(Integer.parseInt(codigo_proveedor.getText()));
        proveedor.setRazon_proveedor(razon_proveedor.getText());
        proveedor.setRuc_proveedor(Integer.parseInt(ruc_proveedor.getText()));
        proveedor.setCi_proveedor(Integer.parseInt(ci_proveedor.getText()));
        proveedor.setTimbrado_proveedor(Integer.parseInt(timbrado_proveedor.getText()));
        proveedor.setVencimiento_proveedor(fecha.format(vencimiento_proveedor.getDate()));
        proveedor.setDireccion_proveedor(direccion_proveedor.getText());
        proveedor.setTelefono_proveedor(telefono_proveedor.getText());
        proveedor.setContacto_proveedor(contacto_proveedor.getText());
        proveedor.setFax_proveedor(fax_proveedor.getText());
        proveedor.setContribuyente_proveedor(contribuyente_proveedor.getToolTipText());
        
        String sql;
         sql="Insert into proveedor ( razon_proveedor ,ruc_proveedor  ,ci_proveedor ,timbrado_proveedor ,vencimiento_proveedor ,direccion_proveedor ,telefono_proveedor ,contacto_proveedor ,fax_proveedor ,contribuyente_proveedor) values "+"(?,?,?,?,?,?,?,?,?,?);";
        try {
            PreparedStatement pat=reg.prepareStatement(sql);
            
            pat.setString(1, proveedor.getRazon_proveedor());
            pat.setInt(2,proveedor.getRuc_proveedor());
            pat.setInt(3, proveedor.getCi_proveedor());
            pat.setInt(4, proveedor.getTimbrado_proveedor());
            pat.setString(5,proveedor.getVencimiento_proveedor());
            pat.setString(6,proveedor.getDireccion_proveedor());
            pat.setString(7,proveedor.getTelefono_proveedor());
            pat.setString(8,proveedor.getContacto_proveedor());
            pat.setString(9,proveedor.getFax_proveedor());
            pat.setString(10,proveedor.getContribuyente_proveedor());
            int var=pat.executeUpdate();
                if (var > 0){
                   JOptionPane.showMessageDialog(null, "Se Registro Con exito");
                   llamar();
                } 
            limpiar();
            
        } catch (SQLException ex) {
            Logger.getLogger(proveedor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_agregar_proveedorActionPerformed

    private void eliminar_proveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eliminar_proveedorActionPerformed
        ConexionMySql con= new ConexionMySql();
        Connection reg= con.conectar();
        System.out.println("Conexion establecida");
        Proveedor proveedor  = new Proveedor();
        proveedor.setCodigo_proveedor(Integer.parseInt(codigo_proveedor.getText()));

        String sql;
        sql = "DELETE FROM proveedor WHERE codigo_proveedor=?;";
        try {
            PreparedStatement pat = reg.prepareStatement(sql);
            pat.setInt(1,proveedor.getCodigo_proveedor());
            pat.executeUpdate();

            JOptionPane.showMessageDialog(null, "Eliminacion Exitosa");
            llamar();
            limpiar();


        } catch (SQLException ex) {
            Logger.getLogger(clientes.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_eliminar_proveedorActionPerformed

    private void editar_proveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editar_proveedorActionPerformed
        ConexionMySql con= new ConexionMySql();
        Connection reg= con.conectar();
        System.out.println("Conexion establecida");
        SimpleDateFormat fecha= new SimpleDateFormat("yyyy-MM-dd");
        Proveedor proveedor  = new Proveedor();
       
        proveedor.setCodigo_proveedor(Integer.parseInt(codigo_proveedor.getText()));
        proveedor.setRazon_proveedor(razon_proveedor.getText());
        proveedor.setRuc_proveedor(Integer.parseInt(ruc_proveedor.getText()));
        proveedor.setCi_proveedor(Integer.parseInt(ci_proveedor.getText()));
        proveedor.setTimbrado_proveedor(Integer.parseInt(timbrado_proveedor.getText()));
        proveedor.setVencimiento_proveedor(fecha.format(vencimiento_proveedor.getDate()));
        proveedor.setDireccion_proveedor(direccion_proveedor.getText());
        proveedor.setTelefono_proveedor(telefono_proveedor.getText());
        proveedor.setContacto_proveedor(contacto_proveedor.getText());
        proveedor.setFax_proveedor(fax_proveedor.getText());
        proveedor.setContribuyente_proveedor(contribuyente_proveedor.getToolTipText());
        
        String sql;
         sql="UPDATE proveedor"+" SET razon_proveedor=?,"+" ruc_proveedor=?,"+" ci_proveedor=?,"+" timbrado_proveedor=?,"+ "vencimiento_proveedor=?,"+"direccion_proveedor=?,"+"telefono_proveedor=?,"+"contacto_proveedor=?,"+"fax_proveedor=?,"+"contribuyente_proveedor=?"+" WHERE codigo_proveedor=?;";
        try {
            PreparedStatement pat=reg.prepareStatement(sql);
            
            pat.setString(1, proveedor.getRazon_proveedor());
            pat.setInt(2,proveedor.getRuc_proveedor());
            pat.setInt(3, proveedor.getCi_proveedor());
            pat.setInt(4, proveedor.getTimbrado_proveedor());
            pat.setString(5,proveedor.getVencimiento_proveedor());
            pat.setString(6,proveedor.getDireccion_proveedor());
            pat.setString(7,proveedor.getTelefono_proveedor());
            pat.setString(8,proveedor.getContacto_proveedor());
            pat.setString(9,proveedor.getFax_proveedor());
            pat.setString(10,proveedor.getContribuyente_proveedor());
            pat.setInt(11, proveedor.getCodigo_proveedor());
            pat.executeUpdate();
            
            JOptionPane.showMessageDialog(null, "Se Actualizo Con exito");
            
            llamar();
            limpiar();
            
        } catch (SQLException ex) {
            Logger.getLogger(proveedor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_editar_proveedorActionPerformed

    private void nuevo_proveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevo_proveedorActionPerformed
        razon_proveedor.setEnabled(true);
        ruc_proveedor.setEnabled(true);
        ci_proveedor.setEnabled(true);
        timbrado_proveedor.setEnabled(true);
        vencimiento_proveedor.setEnabled(true);
        direccion_proveedor.setEnabled(true);
        telefono_proveedor.setEnabled(true);
        contacto_proveedor.setEnabled(true);
        fax_proveedor.setEnabled(true);
        contribuyente_proveedor.setEnabled(true);
        agregar_proveedor.setEnabled(true);
        eliminar_proveedor.setEnabled(true);
        editar_proveedor.setEnabled(true); 
        
        codigo_proveedor.setText("");
        razon_proveedor.setText("");
        ruc_proveedor.setText("");
        ci_proveedor.setText("");
        timbrado_proveedor.setText("");
        vencimiento_proveedor.setDate(null);
        direccion_proveedor.setText("");
        telefono_proveedor.setText("");
        contacto_proveedor.setText("");
        fax_proveedor.setText("");
        contribuyente_proveedor.setToolTipText("");
        
        
    }//GEN-LAST:event_nuevo_proveedorActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new proveedor().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton agregar_proveedor;
    private javax.swing.JButton atras_proveedor;
    private javax.swing.JButton buscar_nombre;
    private javax.swing.JTextField ci_proveedor;
    private javax.swing.JTextField codigo_proveedor;
    private javax.swing.JTextField contacto_proveedor;
    private javax.swing.JComboBox contribuyente_proveedor;
    private javax.swing.JTextField direccion_proveedor;
    private javax.swing.JButton editar_proveedor;
    private javax.swing.JButton eliminar_proveedor;
    private javax.swing.JTextField fax_proveedor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton nuevo_proveedor;
    private javax.swing.JTextField proveedor_busqueda;
    private javax.swing.JTextField razon_proveedor;
    private javax.swing.JTextField ruc_proveedor;
    private javax.swing.JTextField telefono_proveedor;
    private javax.swing.JTextField timbrado_proveedor;
    private com.toedter.calendar.JDateChooser vencimiento_proveedor;
    private javax.swing.JTable vista;
    // End of variables declaration//GEN-END:variables

    private void atras() {
        principal v=new principal();
        v.setVisible(true);
        v.setLocationRelativeTo(this);
        this.dispose();
    }

    private void llamar() {
      ConexionMySql con = new ConexionMySql();
        Connection cnn = con.conectar();
        String[] titulos = {"Codigo","Nombre","RUC","Doc Identidad","Timbrado","Vencimiente","Direccion","Telefono","Contacto","Fax","Contriyuyente"};
        busqueda = new DefaultTableModel(null,titulos);
        String [] registro = new String[12];
        String id = (proveedor_busqueda.getText());
        String sql = "SELECT codigo_proveedor, razon_proveedor ,ruc_proveedor  ,ci_proveedor ,timbrado_proveedor ,vencimiento_proveedor ,direccion_proveedor ,telefono_proveedor ,contacto_proveedor ,fax_proveedor ,contribuyente_proveedor FROM proveedor where razon_proveedor LIKE '%" + id +"%'";
        try
        {
            Statement st = cnn.createStatement();
            ResultSet rs = st.executeQuery(sql);

            while(rs.next()){
                registro[0]= rs.getString(1);
                registro[1]= rs.getString(2);
                registro[2]= rs.getString(3);
                registro[3]= rs.getString(4);
                registro[4]= rs.getString(5);
                registro[5]= rs.getString(6);
                registro[6]= rs.getString(7);
                registro[7]= rs.getString(8);
                registro[8]= rs.getString(9);
                registro[9]= rs.getString(10);
                registro[10]= rs.getString(11);
                
                busqueda.addRow(registro);
            }
            vista.setModel(busqueda);
        }
        catch (SQLException e)
        {
            JOptionPane.showMessageDialog(null, e);

        }    
    }
    String actualizar ="";
    private void PasarTabla(String valor) {
     ConexionMySql con = new ConexionMySql();
      Connection cnn = con.conectar();

      String sql = "SELECT codigo_proveedor, razon_proveedor ,ruc_proveedor  ,ci_proveedor ,timbrado_proveedor ,vencimiento_proveedor ,direccion_proveedor ,telefono_proveedor ,contacto_proveedor ,fax_proveedor ,contribuyente_proveedor FROM proveedor WHERE codigo_proveedor = "+ valor;
      try 
      {
        Statement st = cnn.createStatement();
        ResultSet rs = st.executeQuery(sql);
        if(rs.next()){
        codigo_proveedor.setText(rs.getString(1)) ;
        razon_proveedor.setText(rs.getString(2)) ;
        ruc_proveedor.setText(rs.getString(3)) ;
        ci_proveedor.setText(rs.getString(4)) ;
        timbrado_proveedor.setText(rs.getString(5)) ;
        vencimiento_proveedor.setDate(rs.getDate(6));
        direccion_proveedor.setText(rs.getString(7)) ;
        telefono_proveedor.setText(rs.getString(8)) ;
        contacto_proveedor.setText(rs.getString(9)) ;
        fax_proveedor.setText(rs.getString(10)) ;
        contribuyente_proveedor.setToolTipText(rs.getString(11));
          
        }
      } 
      catch (SQLException e) 
      {
            JOptionPane.showMessageDialog(null, e);
      }
      actualizar = valor;   
    }

    private void limpiar() {
        razon_proveedor.setEnabled(true);
        ruc_proveedor.setEnabled(true);
        ci_proveedor.setEnabled(true);
        timbrado_proveedor.setEnabled(true);
        vencimiento_proveedor.setEnabled(true);
        direccion_proveedor.setEnabled(true);
        telefono_proveedor.setEnabled(true);
        contacto_proveedor.setEnabled(true);
        fax_proveedor.setEnabled(true);
        contribuyente_proveedor.setEnabled(true);
        agregar_proveedor.setEnabled(true);
        eliminar_proveedor.setEnabled(true);
        editar_proveedor.setEnabled(true); 
        
        codigo_proveedor.setText("");
        razon_proveedor.setText("");
        ruc_proveedor.setText("");
        ci_proveedor.setText("");
        timbrado_proveedor.setText("");
        vencimiento_proveedor.setDate(null);
        direccion_proveedor.setText("");
        telefono_proveedor.setText("");
        contacto_proveedor.setText("");
        fax_proveedor.setText("");
        contribuyente_proveedor.setToolTipText("");
    }
}
